package com.blogs.component;

import com.cnblogs.R;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class GetMoreListView extends ListView {
	private LinearLayout mFooterLinearLayout = null; 
	private TextView mFooterTextView = null; 
    private ProgressBar mFooterProgressBar = null; 
    private OnMoreListener moreListener;
	public GetMoreListView(Context context) {
		super(context);
		init(context);
	}
	public GetMoreListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	private void init(Context context) {
		this.setDivider(context.getResources().getDrawable(R.drawable.line_01));
		mFooterLinearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.refresh_list_footer, null); 
        addFooterView(mFooterLinearLayout); 
        mFooterProgressBar = (ProgressBar) findViewById(R.id.refresh_list_footer_progressbar); 
        mFooterTextView = (TextView) mFooterLinearLayout.findViewById(R.id.refresh_list_footer_text); 
        mFooterLinearLayout.setOnClickListener(new OnClickListener() { 
            public void onClick(View v) { 
            	if(moreListener!=null)
            	{
            		mFooterTextView.setText("正在拉取数据...");
            		mFooterProgressBar.setVisibility(View.VISIBLE);
            		moreListener.onGetMore();
            	}
            } 
        }); 
        this.setCacheColorHint(Color.TRANSPARENT);
	}
	public void setonMoreListener(OnMoreListener moreListener)
	{
		this.moreListener=moreListener;
	}
	public interface OnMoreListener
	{
		public void onGetMore();
	}
	public void onMoreComplete()
	{
		mFooterTextView.setText("更多");
		mFooterProgressBar.setVisibility(View.GONE);
	}
	public void setFootNotMore()
	{
		mFooterTextView.setText("没有更多信息");
		this.setFooterDividersEnabled(false);
	}
}
